﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace FileRenamer
{
    /// <summary>
    /// Interaction logic for NumericControl.xaml
    /// </summary>
    public partial class NumericControl : UserControl
    {
        public static readonly DependencyProperty CurrentNumProperty = DependencyProperty.Register(
            "CurrentNum", typeof(int), typeof(NumericControl), 
            new FrameworkPropertyMetadata(0, 
                FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValueChanged, OnValueCoerce, false, 
                UpdateSourceTrigger.PropertyChanged));

        public int CurrentNum
        {
            get { return (int)this.GetValue(CurrentNumProperty); }
            set { this.SetValue(CurrentNumProperty, value); }
        }

        private static object OnValueCoerce(DependencyObject d, object basevalue)
        {
            return (int)basevalue;
        }

        private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            NumericControl control = (NumericControl)d;
            control.NumTextBox.Text = e.NewValue.ToString();
        }

        public NumericControl()
        {
            InitializeComponent();
          //  this.DataContext = this;
            CurrentNum = 0;
            NumTextBox.Text = CurrentNum.ToString();
        }

        private void cmdUp_Click(object sender, RoutedEventArgs e)
        {
            CurrentNum++;
        }

        private void cmdDown_Click(object sender, RoutedEventArgs e)
        {
            if (CurrentNum > 0) CurrentNum--;
        }
    }
}
